﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using TinyERP.Framework;
using TinyERP.Framework.Controls;
using TinyERP.Framework.Validation;
using Bamboo.Core.Common.Logger;

namespace TinyERP.Framework.Controls
{
    public class BasicEditInfoDialog : BaseDialog
    {

        protected Validator validator;
        protected SaveButton saveButton;
        protected CloseButton closeButton;
        protected DeleteButton deleteButton;
        protected Panel buttonPanel;
        protected Panel contentPanel;
        protected FlowLayoutPanel buttonFlowLayout;

        public BasicEditInfoDialog()
        {
            InitializeComponent();
            AddValidationRules();
            WireEvents();
            
        }
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.buttonFlowLayout = new System.Windows.Forms.FlowLayoutPanel();
            this.buttonPanel = new System.Windows.Forms.Panel();
            this.contentPanel = new System.Windows.Forms.Panel();

            this.deleteButton = new TinyERP.Framework.Controls.DeleteButton();
            this.closeButton = new TinyERP.Framework.Controls.CloseButton();
            this.saveButton = new TinyERP.Framework.Controls.SaveButton();


            this.buttonPanel.SuspendLayout();
            this.contentPanel.SuspendLayout();
            this.buttonFlowLayout.SuspendLayout();
            this.SuspendLayout();



            this.deleteButton.AutoSize = true;
            this.deleteButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.deleteButton.Location = new System.Drawing.Point(324, 3);
            this.deleteButton.Name = "deleteButton";
            this.deleteButton.TabIndex = 8;

            this.closeButton.AutoSize = true;
            this.closeButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.closeButton.Location = new System.Drawing.Point(445, 3);
            this.closeButton.Name = "closeButton";
            this.closeButton.TabIndex = 8;

            this.saveButton.AutoSize = true;
            this.saveButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.saveButton.Location = new System.Drawing.Point(389, 3);
            this.saveButton.Name = "saveButton";
            this.saveButton.TabIndex = 9;

            this.buttonFlowLayout.Controls.Add(this.closeButton);
            this.buttonFlowLayout.Controls.Add(this.saveButton);
            this.buttonFlowLayout.Controls.Add(this.deleteButton);
            this.buttonFlowLayout.Dock = System.Windows.Forms.DockStyle.Fill;
            this.buttonFlowLayout.Location = new System.Drawing.Point(0, 0);
            this.buttonFlowLayout.Name = "buttonFlowLayout";
            this.buttonFlowLayout.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
            this.buttonFlowLayout.Size = new System.Drawing.Size(502, 30);
            this.buttonFlowLayout.TabIndex = 9;

            this.buttonPanel.Controls.Add(this.buttonFlowLayout);
            this.buttonPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.buttonPanel.Location = new System.Drawing.Point(0, 375);
            this.buttonPanel.Name = "buttonPanel";
            this.buttonPanel.Size = new System.Drawing.Size(502, 30);
            this.buttonPanel.TabIndex = 8;


            this.contentPanel.Dock = System.Windows.Forms.DockStyle.Fill;
            this.contentPanel.Location = new System.Drawing.Point(0, 0);
            this.contentPanel.Name = "contentPanel";
            this.contentPanel.Size = new System.Drawing.Size(502, 375);
            this.contentPanel.TabIndex = 0;


            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.contentPanel);
            this.Controls.Add(this.buttonPanel);

            this.Size = new System.Drawing.Size(502, 405);
            this.buttonPanel.ResumeLayout(false);
            this.contentPanel.ResumeLayout(false);
            this.contentPanel.PerformLayout();
            this.buttonFlowLayout.ResumeLayout(false);
            this.buttonFlowLayout.PerformLayout();
            this.ResumeLayout(false);


        }

        #endregion
        protected virtual void AddValidationRules()
        {
            validator = new Validator();
            //TODO: use validator to add validation rules on your input controls
            //Example: validator.AddValidationRule(new RequiredFieldRule(txtUserName, "User name"));
        }
        /// <summary>
        /// To validate user input data with default validator, you should override this function to add
        /// more business rule (that can not check by Validator constraints)
        /// </summary>
        /// <returns></returns>
        protected virtual bool ValidateInputData()
        {
            if (!validator.Validate())
            {
                return false;
            }
            return true;
        }
        public virtual void WireEvents()
        {
            this.deleteButton.Click += delegate(object senderObj, EventArgs ev)
            {
                OnDelete();
            };
            this.closeButton.Click += delegate(object senderObj, EventArgs ev)
            {
                OnClose();
            };
            this.saveButton.Click += delegate(object senderObj, EventArgs ev)
            {
                OnSave();
            };
        }
        public virtual void OnSave()
        {

        }
        public virtual void OnDelete()
        {

        }
        protected virtual void LoadEntityInfo()
        {

        }

        public virtual void OnClose()
        {
            InvokeCloseDialog();
        }


        public override void RegisterShortcuts()
        {
            ShortcutHandler.GetInstance().RegisterShortcut(StandardShortcutKey.SAVE, this, "OnSave");
            ShortcutHandler.GetInstance().RegisterShortcut(StandardShortcutKey.CLOSE, this, "OnClose");
            ShortcutHandler.GetInstance().RegisterShortcut(StandardShortcutKey.DELETE, this, "OnDelete");
        }


        public override IButtonControl GetAcceptButton()
        {
            return this.saveButton;
        }
        public override IButtonControl GetCancelButton()
        {
            return this.closeButton;
        }

        

    }
}
